/**
 * Created by Administrator on 2017/7/24.
 */

var userModify = new Object();
var page;
// 查询用户证书
userModify.init = function(userCertificate_page){
    page = userCertificate_page;
    this.initListTable(page);
};

userModify.initListTable= function(){
    var list_url = appPath+"/admin/user/queryCertificateList";

    /*
     * 分页
     * @param param_form 参数form id
     * @param list_url 请求链接
     * @param tbody_id 列表div id
     * @param page_id 分页id
     * @param pageNum 页数
     * @param pageSize 每页条数
     */
    page.init("userCertificateForm", list_url, "userCertificate_tbody", "userCertificate_page", 1, 10);

    //初始化
    page.goPage(1);

    //重写组装方法
    page.list = function(dataList){
        var len = dataList.length;
        var inner = "", item;
        for(var i=0; i< len; i++) {
            item = dataList[i];
            inner += '<tr>';

            var certificateName = item.certificateName;
            if (certificateName == '' || certificateName == undefined || certificateName == null) {
                inner += "<td width='100'>certificateName</td>";
            } else {
                inner += "<td width='100'><span>" + certificateName + "</span></td>";
            }
            inner += "<td width='80'><span>" + item['certificateType'] + "</span></td>";
            inner += "<td width='70'><span>" + TimeUtil.longMsTimeConvertToDateTime(item['registerDate']) + "</span></td>";
            inner += "<td width='70'><span>" + TimeUtil.longMsTimeConvertToDateTime(item['availabeDate']) + "</span></td>";
            var remark = item['remark'];
            if(remark.length < 20){
                inner += "<td title='"+ remark +"' width='100' ><div alt='"+ remark +"' style='width: 80px;text-align: center;'>" +remark + "</div></td>";
            }else{
                inner += "<td title='"+ remark +"' width='100' ><div alt='"+ remark +"' style='width: 80px;text-align: center;'>" +remark.substr(0,20) + "...</div></td>";
            }

            var certificateStatus = item.certificateStatus;
            if(certificateStatus == 1){
                inner += "<td width='70'><span>" + "有效" + "</span></td>";
            }else if(certificateStatus == 2){

                inner += "<td width='70' class=\"text-yellow\"><span>" + "即将失效" + "</span></td>";
            }else{

                inner += "<td width='70'><span class=\"text-red\">" + "无效" + "</span></td>";
            }
            inner += '<td width="150">';
            /*inner += '<a href="javascript:toCer(\''+item['id']+'\')" class="a a-info" target="_blank">附件预览</a>';*/
            inner += '<a href="javascript:userModify.userCertificateInfo(\''+item['id']+'\')" class="a a-info" target="_blank">详情</a>';
            inner += '<a href="javascript:userModify.userCertificateModify(\''+item['id']+'\')" class="a a-info" target="_blank">修改</a>'
            inner += '<a href="javascript:deleteCer(\''+item['id']+'\')" class="a a-info" target="_blank">删除</a>'
            inner += '</td>';
            inner += '</tr>';

        }
        return inner;
    }

};
// 持证详情
toCer =function (id){
    layer.open({
        type: 2,
        title: '证书详情',
        area: ['700px', '900px'],		//弹出层大小
        scrollbar: false,				//false隐藏滑动块
        content: [appPath + '/admin/certificate/certificateInfo?id=' +id, 'yes']
    });
};
userModify.userCertificateInfo = function (varId) {
    window.location.href = appPath + "/admin/certificate/userCertificateInfo?varId=" + varId;
}
userModify.userCertificateModify = function (varId) {
     window.location.href = appPath + "/admin/certificate/userCertificateModify?varId=" + varId;
}